package designparttern.singleton;

/**
 * 静态内部类式
 * 利用静态内部类不会由于外部类加载而加载的特性
 * 只有当调用到 {@link InnerClassSingleton#getInstance()} 时才会进行初始化
 * 实现懒加载
 *
 * @author hck
 */
public class InnerClassSingleton {
    static {
        System.out.println("load singleton out class");
    }

    private InnerClassSingleton() {
    }

    private static class InnerFactory {
        private static final InnerClassSingleton INSTANCE = new InnerClassSingleton();
        static {
            System.out.println("load singleton inner class");
        }
    }

    public static InnerClassSingleton getInstance() {
        return InnerFactory.INSTANCE;
    }
}
